<!-- exp_15_1.html 实验15-1 -->
<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
<html>
    <head>
        <title> 表单处理事件 </title>
        <style type="text/css">
            fieldset
            {
                margin:20px auto;
                background:#663399;
                width:300px;
                height:200px;
                padding:20px auto;
                color:white;
                text-align:center;
            }
            legend
            {
                color:black;
                font-size:24px;
                font-weight:bold;
                text-align:center;
            }
        </style>
        <script type="text/javascript">
            function checklogin()
            {
                var username=document.getElementById("myname").value;
                var pwd=document.getElementById("mypwd").value;
                if(username=="")  //两者中有一个为空
                {
                    alert("用户名不能为空！！");
                    document.getElementById("myname").focus();
                    return false;
                }
                else
                {
                    if(username.length<8||username.length>20)
                    {
                        alert("用户名太短，应在8~20个字符之间！！");
                        document.getElementById("myname").focus();
                        return false;
                    }
                }
                if (pwd=="")  //两者中有一个为空
                {
                    alert("密码不能为空！！");
                    document.getElementById("mypwd").focus();
                    return false;
                }
                else
                {
                    if(pwd.length<8||pwd.length>20)
                    { 
                        alert("密码太短，应在6~20个字符之间！！");
                        document.getElementById("mypwd").focus();
                        return false;
                    }
                }
                return true;
            }
        </script>
    </head>
    <body>
        <form name="loginform" method="post" action="loginindex.html" onsubmit="return checklogin()">
            <fieldset>
                <legend>用户登录</legend>
                <br><br>
                <label>用户名</label>
                <input type="text" name="" id="myname" ><br><br>
                <label>密&nbsp;&nbsp;码</label>
                <input type="password" name="" id="mypwd" ><br><br><br>
                <input type="submit" value="提交"><input type="reset">
            </fieldset>
        </form>
    </body>
</html>
